﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace ServisniList.Rukovatelji
{
    public static class Logiranje
    {
        public static void SaveToLogFile(string poruka, Exception exception)
        {
            if (!File.Exists("ServisniList.log"))
            {
                File.Create("ServisniList.log");
            }

            try
            {
                using (StreamWriter sw = new StreamWriter(new FileStream("ServisniList.log", FileMode.Append, FileAccess.Write, FileShare.ReadWrite)))
                {
                    //Writes the method name with the exception and writes the exception underneath
                    sw.WriteLine(String.Format("{0} ({1}) - Opis: {2}", DateTime.Now.ToShortDateString(), DateTime.Now.ToShortTimeString(), poruka));
                    sw.WriteLine(exception.StackTrace.ToString()); sw.WriteLine("");
                }
            }
            catch
            {

            }
        }
    }
}
